package com.isoft.c2team3service2.controller;

import com.isoft.c2team3service2.bean.ResponseData;
import com.isoft.c2team3service2.service.FileService;
import com.isoft.c2team3service2.util.FileUtil;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/file")
public class FileController extends BaseController{

    @Autowired
    private FileService fileService;

    //上传头像
    @PostMapping("/rephoto")
    public String rePhoto(MultipartFile file ,String email){
        if (email == null ||file == null) {
            return null;
        }
        if (email.contains(",")) {
            email = email.split(",")[0]; // 取第一个 email
        }
        return fileService.rePhoto(file,email);
    }

    //上传文件
    @PostMapping("/upload")
    public ResponseData<String> upload(MultipartFile file){
        if (file == null) {
            return new ResponseData<>(5001, "信息不完整", null);
        }
        String  url = fileService.upload(file);
        return resultT(url,"上传文件");
    }
}
